
#返回闭包不能引用循环变量，请改写count()函数，让它正确返回能计算1x1、2x2、3x3的函数。

#方法1
def count():
    fs = []
    for i in range(1, 4):
        def f(i):
            def g():
                return i**2
            return g
        fs.append(f(i))
    return fs

f1, f2, f3 = count()
print f1(), f2(), f3()


#方法2 lambda
def count():
    fs = []
    for i in range(1, 4):
        f = lambda x:lambda: x**2
        fs.append(f(i))
    return fs

f1, f2, f3 = count()
print f1(), f2(), f3()



#方法3 lambda 进阶
count = [(lambda x:lambda: x**2)(i) for i in range(1, 4)]
f1, f2, f3 = count
print f1(), f2(), f3()


